import path from 'path';
import { defineConfig } from 'umi';
import { proxy } from './proxy';
import { routes } from './routes';

const { UMI_ENV = 'dev', API_PREFIX, PUBLIC_PATH } = process.env;

export default defineConfig({
  publicPath: PUBLIC_PATH,
  base: '/',
  hash: true,
  antd: {},
  history: {
    type: 'browser',
  },
  title: 'umi-template',
  dva: {
    hmr: true,
  },
  layout: false,
  locale: {
    default: 'zh-CN',
    antd: true,
    baseNavigator: true,
  },
  ignoreMomentLocale: true,
  inlineLimit: 4000,
  nodeModulesTransform: {
    type: 'none',
  },
  routes,
  proxy: proxy[UMI_ENV] || proxy['dev'],
  fastRefresh: {},
  theme: {
    'root-entry-name': 'variable',
    'border-radius-base': '4px',
  },
  cssLoader: {
    localsConvention: 'camelCase',
  },
  targets: {
    ie: 11,
  },
  terserOptions: {
    compress: {
      pure_funcs: ['console.log'],
    },
  },
  dynamicImport: {
    loading: '@/components/PageLoading',
  },
  define: {
    'process.env.API_PREFIX': API_PREFIX,
    'process.env.PUBLIC_PATH': PUBLIC_PATH,
  },
  lessLoader: {
    modifyVars: {
      hack: `true; @import "~@/var.less";`,
    },
  },
  chainWebpack(config: any) {
    config.module
      .rule('lint')
      .test(/.(js|jsx|mjs|ts|tsx)$/)
      .pre()
      .include.add(path.resolve(__dirname, '../src'))
      .end()
      .use('eslint')
      .loader(require.resolve('eslint-loader'))
      .options({
        eslintPath: require.resolve('eslint'),
      });
  },
});
